package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service // dubbo的
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    // 保存用户
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    // 根据手机号查询用户
    @Override
    public User findByPhone(String phone) {
        // 构建条件
        QueryWrapper qw = new QueryWrapper<User>();
        qw.eq("phone", phone);
        // 基于条件查询
        return userMapper.selectOne(qw);
    }
}
